Skip to content

Method: ClassDataPropertyComputer(OWLClass, OWLDataProperty, IntegrityConstraintSet, OWLOntology)

1: /*
2: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.jopa.owl2java;
19:
20: import cz.cvut.kbss.jopa.ic.api.DataParticipationConstraint;
21: import cz.cvut.kbss.jopa.ic.api.DataRangeConstraint;
22: import org.semanticweb.owlapi.apibinding.OWLManager;
23: import org.semanticweb.owlapi.model.OWLClass;
24: import org.semanticweb.owlapi.model.OWLDataProperty;
25: import org.semanticweb.owlapi.model.OWLDatatype;
26: import org.semanticweb.owlapi.model.OWLOntology;
27:
28: public class ClassDataPropertyComputer extends ClassPropertyComputer<DataParticipationConstraint, OWLDatatype> {
29:
30: public ClassDataPropertyComputer(
31: final OWLClass clazz,
32: final OWLDataProperty prop,
33: final IntegrityConstraintSet set,
34: final OWLOntology ontology
35: ) {
36: boolean hasFiller = true;
37: set.getClassDataIntegrityConstraints(clazz, prop).forEach(integrityConstraint -> {
38: if (integrityConstraint instanceof DataParticipationConstraint) {
39: constraints.add((DataParticipationConstraint) integrityConstraint);
40: } else if (integrityConstraint instanceof DataRangeConstraint) {
41: this.filler = ((DataRangeConstraint) integrityConstraint).getRange();
42: }
43: });
44:
45:• if (filler == null) {
46: hasFiller = false;
47: this.filler = ontology.getOWLOntologyManager().getOWLDataFactory().getRDFPlainLiteral();
48: }
49:
50:• if (constraints.isEmpty() && !hasFiller) {
51: this.card = Card.NO;
52: } else {
53: this.card = Card.MULTIPLE;
54:• for (final DataParticipationConstraint opc : constraints) {
55: final OWLDatatype dt2 = opc.getObject();
56:• if ((getFiller().equals(dt2) ||
57:• dt2.equals(OWLManager.getOWLDataFactory().getTopDatatype())) && opc.getMax() == 1) {
58: this.card = Card.ONE;
59: return;
60: }
61: }
62: }
63: }
64: }